package com.banban.user.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.banban.user.config.SmsConfig;
import com.banban.user.domain.ConversationLog;
import com.banban.user.domain.SysUser;
import com.banban.user.domain.UserLoginRecord;
import com.banban.user.domain.UserProfile;
import com.banban.user.dto.*;
import com.banban.user.exception.BusinessException;
import com.banban.user.exception.code.BaseResponseCode;
import com.banban.user.mapper.ConversationLogMapper;
import com.banban.user.mapper.SysUserMapper;
import com.banban.user.mapper.UserProfileMapper;
import com.banban.user.service.AliyunOssService;
import com.banban.user.service.UserCidService;
import com.banban.user.service.UserLoginRecordService;
import com.banban.user.service.UserService;
import com.banban.user.util.RedisUtil;
import com.banban.user.util.TripleDESUtil;
import com.banban.user.util.UniqueIDUtil;
import com.banban.user.vo.ConversationSelectVO;
import com.banban.user.vo.UserInfoVO;
import com.banban.user.vo.UserPageVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.TimeUnit;

@Service
@Slf4j
public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements UserService {

    @Resource
    private ConversationLogMapper conversationLogMapper;

    @Resource
    private SysUserMapper sysUserMapper;

    @Resource
    private RedisUtil redisUtils;

    @Resource
    private AliyunOssService aliyunOssService;

    @Value("${oss.Bucket}")
    private String Bucket;

    @Value("${spring.profiles.active}")
    private String env;

    @Value("${secretKey3DES}")
    private String secretKey3DES;

    @Resource
    private UserProfileMapper userProfileMapper;

    @Autowired
    private UserCidService userCidService;

    @Autowired
    private UserLoginRecordService loginRecordService;

    //登录认证
    private static final String CODE_VERIFY_KEY = "CODE_VERIFY_KEY_";

    //注册使用
    private static final String CODE_VERIFY_REGISTER_KEY = "CODE_VERIFY_REGISTER_KEY_";

    //换绑手机号
    private static final String NOT_BIND_PHONE_KEY = "NOT_BIND_PHONE_KEY_";

    //更换新手机号
    private static final String UPDATE_PHONE_KEY = "UPDATE_PHONE_KEY_";

    public static final String RESOURCE_OSS_KEY = "resource/staticResource/";

    @Value("${defaultPicUrl}")
    private String defaultPicUrl;

    private static final String BANBAN_USER_MESSAGE = "BANBAN_USER_MESSAGE_";

    @Resource
    private RedisUtil redisUtil;

    @Override
    public Integer getCodeVerify(String phone) throws Exception {
        if (StringUtils.isEmpty(phone)) {
            throw new BusinessException("手机号码不能为空");
        }
        if (redisUtils.get(CODE_VERIFY_KEY + phone) != null || redisUtils.get(CODE_VERIFY_REGISTER_KEY + phone) != null) {
            throw new BusinessException("验证码已发送，请1分钟后重试");
        }

        SysUser sysUser = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getPhone, phone));
        if (sysUser != null && sysUser.getStatus() == 0) {
            throw new BusinessException("该手机号已锁定！");
        }
        //调用下发短信接口下发短信验证码
        if ("dev".equals(env)) {
            //开发环境
            redisUtils.set(CODE_VERIFY_KEY + phone, "1234", 1L, TimeUnit.MINUTES);
            return 0;
        } else {
            //生产环境
            Random random = new Random();
            int randomNumber = random.nextInt(10000); // 生成 0 到 9999 之间的随机数
            String code = String.format("%04d", randomNumber); // 格式化为4位数字，不足部分补0
            //调用短信接口
            String result =  sendMessage(phone, code);
            if (!"OK".equals(result)){
                throw new BusinessException("短信发送失败");
            }
            redisUtils.set(CODE_VERIFY_KEY + phone, code, 1L, TimeUnit.MINUTES);
            return 0;
        }
    }

    private String sendMessage(String phone, String code) throws Exception {
        return SmsConfig.sendSms(phone, code);
//        MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
//        map.add("mobile", phone);
//        map.add("param", "**code**:" + code + ",**minute**:5");
//        map.add("smsSignId", "2e65b1bb3d054466b82f0c9d125465e2");
//        map.add("templateId", "908e94ccf08b4476ba6c876d13f084ad");
//        Map<String, String> header = new HashMap<>();
//        header.put("Authorization", "APPCODE a1fab91d1ede4eb7be35d46606c58f10");
//        String s = restTemplateUtil.postFormDataAndHeader("https://gyytz.market.alicloudapi.com/sms/smsSend", map, header);
//        log.info("短信发送结果：{}", s);
    }

    @Override
    public String getDefaultPicUrl() {
        return defaultPicUrl;
    }

    @Override
    public void updateUserInfo(UpdateUserDTO dto) {
        String loginIdAsString = StpUtil.getLoginIdAsString();
        dto.setId(loginIdAsString);
        sysUserMapper.updateByCondition(dto);
    }

    @Override
    public void notBindNfc(String nfcId) {
        String loginIdAsString = StpUtil.getLoginIdAsString();
        SysUser sysUser = sysUserMapper.selectById(loginIdAsString);
        String nfcIdOrigin = sysUser.getNfcId();
        if (StringUtils.isBlank(nfcIdOrigin)) {
            throw new BusinessException("未绑定NFC");
        }
        // 将nfc_id字符串分割为列表
        List<String> nfcIdList = new ArrayList<>();
        for (String id : nfcIdOrigin.split(",")) {
            if (!id.trim().isEmpty()) {
                nfcIdList.add(id.trim());
            }
        }
        // 移除指定的nfc_id
        nfcIdList.remove(nfcId);

        // 将更新后的nfc_id列表拼接回字符串
        String updatedNfcIds = String.join(",", nfcIdList);

        sysUserMapper.updateById(SysUser.builder().id(loginIdAsString).nfcId(updatedNfcIds).build());
    }

    @Override
    public void logout() {
        StpUtil.logout();
    }

    @Override
    public Integer nfcLogin(String nfcId) {
        try {
            nfcId = TripleDESUtil.decrypt(nfcId, secretKey3DES);
        } catch (Exception e) {
            log.error("nfcId解密失败", e);
            throw new BusinessException("nfcId非法");
        }
        SysUser sysUser = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().like(SysUser::getNfcId, nfcId));
        if (sysUser == null) {
            log.info("nfcLogin nfcId 不存在：{}", nfcId);
            return 1;
        }
        if (sysUser.getStatus() == 0) {
            throw new BusinessException("账号已被锁定");
        }
        String id = sysUser.getId();
        StpUtil.login(id);
        //新增登录记录
        UserLoginRecord loginRecord = new UserLoginRecord();
        loginRecord.setUserId(id);
        loginRecordService.save(loginRecord);
        //设置用户画像
        List<UserProfile> userProfiles = userProfileMapper.selectByUserId(id);
        if (userProfiles != null && !userProfiles.isEmpty()){
            Map<String, String> map = new HashMap<>();
            for (UserProfile userProfile : userProfiles) {
                map.put(userProfile.getField(), userProfile.getValue());
            }
            redisUtil.set(BANBAN_USER_MESSAGE + id, map);
        }
        return 0;
    }

    @Override
    public IPage<UserPageVO> userPage(UserPageDTO dto) {
        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(dto.getPhone())) {
            queryWrapper.like("phone", dto.getPhone());
        }
        if (StringUtils.isNotBlank(dto.getNickName())) {
            queryWrapper.like("nick_name", dto.getNickName());
        }
        if (StringUtils.isNotBlank(dto.getRealName())) {
            queryWrapper.like("real_name", dto.getRealName());
        }
        if (dto.getSex() != null) {
            queryWrapper.eq("sex", dto.getSex());
        }
        if (dto.getStatus() != null) {
            queryWrapper.eq("status", dto.getStatus());
        }
        if (dto.getCreateWhere() != null) {
            queryWrapper.eq("create_where", dto.getCreateWhere());
        }
        if (StringUtils.isNotBlank(dto.getStartTime()) && StringUtils.isNotBlank(dto.getEndTime())) {
            queryWrapper.between("create_time", dto.getStartTime(), dto.getEndTime());
        }
        queryWrapper.eq("deleted", 1);

        queryWrapper.orderByDesc("create_time");
        Page<SysUser> page = this.page(dto.getQueryPage(), queryWrapper);
        return page.convert(item -> {
            UserPageVO userPageVO = new UserPageVO();
            BeanUtils.copyProperties(item, userPageVO);
            return userPageVO;
        });
    }

    @Override
    public UserPageVO getUserInfoById(String id) {
        SysUser sysUser = sysUserMapper.selectById(id);
        if (sysUser == null) {
            throw new BusinessException("用户不存在");
        }
        if (sysUser.getDeleted() == 0) {
            throw new BusinessException("用户不存在");
        }
        UserPageVO userPageVO = new UserPageVO();
        BeanUtils.copyProperties(sysUser, userPageVO);
        return userPageVO;
    }

    @Override
    public void updateUserInfoById(UpdateUserDTO dto) {
        SysUser sysUser = sysUserMapper.selectById(dto.getId());
        if (sysUser == null) {
            throw new BusinessException("用户不存在");
        }
        if (sysUser.getDeleted() == 0) {
            throw new BusinessException("用户不存在");
        }
        sysUserMapper.updateByCondition(dto);
    }

    @Override
    public void lockUser(UpdateUserDTO dto) {
        SysUser sysUser = sysUserMapper.selectById(dto.getId());
        if (sysUser == null) {
            throw new BusinessException("用户不存在");
        }
        if (sysUser.getDeleted() == 0) {
            throw new BusinessException("用户不存在");
        }
        sysUserMapper.lockUser(dto);
    }

    @Override
    public void registerAndLogin(RegisterDTO dto) {
        String phone = dto.getPhone();
        SysUser sysUserOne = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getPhone, phone));
        if (sysUserOne != null) {
            throw new BusinessException("该手机号已注册！");
        }
//        String code = (String) redisUtils.get(CODE_VERIFY_REGISTER_KEY + phone);
//        if (StringUtils.isBlank(code)) {
//            throw new BusinessException("验证码未发送或已过期");
//        }
//        if (!code.equals(dto.getRandomCode())){
//            throw new BusinessException("验证码错误，请重试");
//        }
        String nfcId = dto.getNfcId();
        if (StringUtils.isNotBlank(nfcId)){
            String randomCode = dto.getRandomCode();
            if (StringUtils.isBlank(randomCode)){
                throw new BusinessException("请输入验证码");
            }
            Object o = redisUtils.get(CODE_VERIFY_KEY + dto.getPhone());
            if (o == null) {
                throw new BusinessException("验证码未发送或已过期");
            }
            if (!o.equals(dto.getRandomCode())) {
                throw new BusinessException("验证码错误");
            }
        }

        SysUser sysUser = new SysUser();
        sysUser.setUsername(phone);
        sysUser.setPhone(phone);
        sysUser.setRealName(dto.getRealName());
        sysUser.setNickName(dto.getNickName());
        sysUser.setSex(dto.getSex());
        sysUser.setIdCard(dto.getIdCard());
        sysUser.setAddress(dto.getAddress());
        sysUser.setDeptId("1904913314932027393");//用户组织
        sysUser.setStatus(1);
        sysUser.setDeleted(1);
//        sysUser.setCreateId(StpUtil.getLoginIdAsString());
        if (StringUtils.isNotBlank(nfcId)) {
            sysUser.setNfcId(nfcId);
        }
//        sysUser.setCreateId(StpUtil.getLoginIdAsString());
        sysUserMapper.insert(sysUser);
        StpUtil.login(sysUser.getId());

        //如果cid不为空，则更新用户cid表
        String cid = dto.getCid();
        if (StringUtils.isNotBlank(cid)){
            userCidService.updateUserCid(sysUser.getId(),cid);
        }
        //添加用户登录记录
        UserLoginRecord loginRecord = new UserLoginRecord();
        loginRecord.setUserId(sysUser.getId());
        if (dto.getLoginWhere() != null){
            loginRecord.setLoginWhere(dto.getLoginWhere());
        }
        loginRecordService.save(loginRecord);
    }

    @Override
    public void notBindPhoneGetCode(String phone) throws Exception {
        if (StringUtils.isEmpty(phone)) {
            throw new BusinessException("手机号码不能为空");
        }
        SysUser sysUser = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getPhone, phone));
        if (sysUser == null) {
            throw new BusinessException("该手机号未注册！");
        }
        if (sysUser.getStatus() == 0) {
            throw new BusinessException("该手机号已锁定！");
        }
        if (redisUtils.get(NOT_BIND_PHONE_KEY + phone) != null) {
            throw new BusinessException("验证码已发送，请1分钟后重试");
        }

        //调用下发短信接口下发短信验证码
        if (env.equals("dev")) {
            //开发环境
            redisUtils.set(NOT_BIND_PHONE_KEY + phone, "1234", 1L, TimeUnit.MINUTES);
        } else {
            //生产环境
            Random random = new Random();
            int randomNumber = random.nextInt(10000); // 生成 0 到 9999 之间的随机数
            String code = String.format("%04d", randomNumber); // 格式化为4位数字，不足部分补0
            //调用短信接口
            String result =  sendMessage(phone, code);
            if (!"OK".equals(result)){
                throw new BusinessException("短信发送失败");
            }
            redisUtils.set(NOT_BIND_PHONE_KEY + phone, code, 1L, TimeUnit.MINUTES);
        }
    }

    @Override
    public void updatePhoneGetCode(String phone) throws Exception {

        SysUser sysUser = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getPhone, phone));
        if (sysUser != null) {
            throw new BusinessException("该手机号已注册");
        }

        if (redisUtils.get(UPDATE_PHONE_KEY + phone) != null) {
            throw new BusinessException("验证码已发送，请1分钟后重试");
        }

        //调用下发短信接口下发短信验证码
        if (env.equals("dev")) {
            //开发环境
            redisUtils.set(UPDATE_PHONE_KEY + phone, "1234", 1L, TimeUnit.MINUTES);
        } else {
            //生产环境
            Random random = new Random();
            int randomNumber = random.nextInt(10000); // 生成 0 到 9999 之间的随机数
            String code = String.format("%04d", randomNumber); // 格式化为4位数字，不足部分补0
            //调用短信接口
            String result =  sendMessage(phone, code);
            if (!"OK".equals(result)){
                throw new BusinessException("短信发送失败");
            }
            redisUtils.set(UPDATE_PHONE_KEY + phone, code, 1L, TimeUnit.MINUTES);
        }
    }

    @Override
    public void updatePhone(UpdatePhoneDTO dto) {
        String phoneOrigin = dto.getPhoneOrigin();
        String phoneNew = dto.getPhoneNew();
        String randomCodeOrigin = dto.getRandomCodeOrigin();
        String randomCodeNew = dto.getRandomCodeNew();
        if (phoneOrigin.equals(phoneNew)) {
            throw new BusinessException("原手机号不能与新手机号一致");
        }
        if (redisUtils.get(NOT_BIND_PHONE_KEY + phoneOrigin) == null) {
            throw new BusinessException("验证码未发送或已过期");
        }
        if (!redisUtils.get(NOT_BIND_PHONE_KEY + phoneOrigin).equals(randomCodeOrigin)) {
            throw new BusinessException("验证码错误");
        }
        if (redisUtils.get(UPDATE_PHONE_KEY + phoneNew) == null) {
            throw new BusinessException("验证码未发送或已过期");
        }
        if (!redisUtils.get(UPDATE_PHONE_KEY + phoneNew).equals(randomCodeNew)) {
            throw new BusinessException("验证码错误");
        }
        SysUser sysUser = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getPhone, phoneOrigin));
        if (sysUser == null) {
            throw new BusinessException("用户不存在");
        }
        sysUser.setPhone(phoneNew);
        sysUserMapper.updateById(sysUser);
    }

    @Override
    public List<ConversationSelectVO> getHistory() {
        String loginIdAsString = StpUtil.getLoginIdAsString();
        List<ConversationLog> list = conversationLogMapper.selectList(Wrappers.<ConversationLog>lambdaQuery().eq(ConversationLog::getCreateBy, loginIdAsString).orderByAsc(ConversationLog::getCreateTime));
        List<ConversationSelectVO> vos = new ArrayList<>();
        for (ConversationLog conversationLog : list) {
            ConversationSelectVO conversationSelectVO = new ConversationSelectVO();
            BeanUtils.copyProperties(conversationLog, conversationSelectVO);
            vos.add(conversationSelectVO);
        }
        return vos;
    }

    @Override
    public void deleteUser(UpdateUserDTO dto) {
        sysUserMapper.deleteById(dto.getId());
    }

    @Override
    public void nfcLoginGetCode(String phone) throws Exception {
        if (redisUtils.get(CODE_VERIFY_REGISTER_KEY + phone) != null) {
            throw new BusinessException("验证码已发送，请1分钟后重试");
        }
        //调用下发短信接口下发短信验证码
        if ("dev".equals(env)) {
            //开发环境
            redisUtils.set(CODE_VERIFY_REGISTER_KEY + phone, "1234", 1L, TimeUnit.MINUTES);
        } else {
            //生产环境
            Random random = new Random();
            int randomNumber = random.nextInt(10000); // 生成 0 到 9999 之间的随机数
            String code = String.format("%04d", randomNumber); // 格式化为4位数字，不足部分补0
            //调用短信接口
            String result =  sendMessage(phone, code);
            if (!"OK".equals(result)){
                throw new BusinessException("短信发送失败");
            }
            redisUtils.set(CODE_VERIFY_REGISTER_KEY + phone, code, 1L, TimeUnit.MINUTES);
        }
    }

    @Override
    public List<String> getHistoryDate() {
        String userId = StpUtil.getLoginIdAsString();
        List<String> dates = conversationLogMapper.getHistoryDateById(userId);
        if (dates != null && !dates.isEmpty()){
            return dates;
        }
        return Collections.emptyList();
    }

    @Override
    public List<ConversationSelectVO> getHistoryByDate(GetHistoryByDateDTO dto) {
        String userId = StpUtil.getLoginIdAsString();
        dto.setUserId(userId);
        List<ConversationSelectVO> vos = conversationLogMapper.getHistoryByDate(dto);
        if (vos != null && !vos.isEmpty()){
            return vos;
        }
        return Collections.emptyList();
    }

    @Override
    public Integer verifyCodeLogin(CodeVerifyLoginDTO dto) {
        Object o = redisUtils.get(CODE_VERIFY_KEY + dto.getPhone());
        if (o == null) {
            throw new BusinessException("验证码未发送或已过期");
        }
        if (!o.equals(dto.getRandomCode())) {
            throw new BusinessException("验证码错误");
        }
        SysUser sysUser = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getPhone, dto.getPhone()));
        if (sysUser == null) {
            log.info("用户不存在，开始注册");
            return 1;
        }
        if (sysUser.getStatus() == 2) {
            throw new BusinessException(BaseResponseCode.USER_LOCK);
        }
        //saToken
        String id = sysUser.getId();
        StpUtil.login(id);
        //如果cid不为空，则更新用户cid表
        String cid = dto.getCid();
        if (StringUtils.isNotBlank(cid)){
            userCidService.updateUserCid(id,cid);
        }
        //添加用户登录记录
        UserLoginRecord loginRecord = new UserLoginRecord();
        loginRecord.setUserId(id);
        if (dto.getLoginWhere() != null){
            loginRecord.setLoginWhere(dto.getLoginWhere());
        }
        loginRecordService.save(loginRecord);
        //设置用户画像
        List<UserProfile> userProfiles = userProfileMapper.selectByUserId(id);
        if (userProfiles != null && !userProfiles.isEmpty()){
            Map<String, String> map = new HashMap<>();
            for (UserProfile userProfile : userProfiles) {
                map.put(userProfile.getField(), userProfile.getValue());
            }
            redisUtil.set(BANBAN_USER_MESSAGE + id, map);
        }
        redisUtils.delete(CODE_VERIFY_KEY + dto.getPhone());
        return 0;
    }

    @Override
    public UserInfoVO getUserInfo() {
        SysUser sysUser = sysUserMapper.selectById(StpUtil.getLoginIdAsString());
        if (sysUser != null) {
            UserInfoVO userInfoVO = new UserInfoVO();
            BeanUtils.copyProperties(sysUser, userInfoVO);
            if (StringUtils.isNotBlank(sysUser.getNfcId())) {
                userInfoVO.setNfcIds(Arrays.asList(sysUser.getNfcId().split(",")));
            }
            return userInfoVO;
        }
        return null;
    }

    @Override
    public String uploadPic(MultipartFile file) {
        //调用阿里云oss上传图片并返回图片地址
        String fileName = file.getOriginalFilename();
        String osskey = RESOURCE_OSS_KEY + UniqueIDUtil.generateId() + fileName;
        String url = null;
        try {
            url = aliyunOssService.uploadFile(Bucket, osskey, file.getInputStream());
        } catch (IOException e) {
            log.error("上传图片失败", e);
        }
        return url;
    }

    @Override
    public void registerNew(RegisterDTO dto) {
        SysUser sysUserOne = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getPhone, dto.getPhone()));
        if (sysUserOne != null) {
            throw new BusinessException("该手机号已注册！");
        }
        SysUser sysUser = new SysUser();
        sysUser.setUsername(dto.getPhone());
        sysUser.setPhone(dto.getPhone());
        sysUser.setRealName(dto.getRealName());
        sysUser.setNickName(dto.getNickName());
        sysUser.setSex(dto.getSex());
        sysUser.setIdCard(dto.getIdCard());
        sysUser.setAddress(dto.getAddress());
        sysUser.setDeptId("1904913314932027393");//用户组织
        sysUser.setStatus(1);
        sysUser.setDeleted(1);
//        sysUser.setCreateId(StpUtil.getLoginIdAsString());
        if (StringUtils.isNotBlank(dto.getNfcId())) {
            sysUser.setNfcId(dto.getNfcId());
        }
        sysUser.setCreateId(StpUtil.getLoginIdAsString());
        sysUserMapper.insert(sysUser);
    }

    @Override
    public void bindNfc(String nfcId) {
        String loginIdAsString = StpUtil.getLoginIdAsString();
        if (StringUtils.isEmpty(nfcId)) {
            throw new BusinessException("nfcId不能为空");
        }
        SysUser sysUser = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().like(SysUser::getNfcId, nfcId));
        if (sysUser != null) {
            throw new BusinessException("该nfc设备已绑定其他账号");
        }
        SysUser sysUser1 = sysUserMapper.selectById(loginIdAsString);
        String nfcIdOrigin = sysUser1.getNfcId();
        if (StringUtils.isEmpty(nfcIdOrigin)) {
            sysUser1.setNfcId(nfcId);
            sysUserMapper.updateById(sysUser1);
        } else {
            String[] split = nfcIdOrigin.split(",");
            if (split.length == 10) {
                throw new BusinessException("nfc设备已满");
            }
            String nfcIdNew = nfcIdOrigin + "," + nfcId;
            sysUser1.setNfcId(nfcIdNew);
            sysUserMapper.updateById(sysUser1);
        }
    }
}
